﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OleDb;

public partial class listDate : MyPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["channel"] != null)
        {
            load();
        }
    }
    void load()
    {
        String sql = "select  newId,title,img,content,addDate from news where channelid in (select channel_id from channel where pageLocation='" + Request["channel"] + "') order by addDate desc";

        OleDbConnection conn = DB.conn();
        if (conn != null)
        {
            conn.Open();
            OleDbDataAdapter adapter = new OleDbDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            try
            {
                adapter.Fill(ds, "dataTable");
                PagedDataSource objPage = new PagedDataSource();
                objPage.DataSource = ds.Tables["dataTable"].DefaultView;
                objPage.AllowPaging = true;
                objPage.PageSize = 5;
                int CurPage;
                if (Request["page"] != null)
                {
                    CurPage = Convert.ToInt32(Request["page"]);
                }
                else
                {
                    CurPage = 1;
                }

                objPage.CurrentPageIndex = CurPage - 1;
                datas.DataSource = objPage;
                datas.DataBind();

                base.Pager(RecordCount, PageCount, Pageindex, pageSelect,
                    FirstPage, PrevPage, NextPage, LastPage,
                    objPage.DataSourceCount, objPage.PageCount, CurPage, "&channel=" + Request["channel"]);
            }
            catch (Exception error)
            {
                Response.Write(error.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
    }
}